/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl;

import cz.muni.fi.diplomka.datalayer.dao.PlayerDao;
import cz.muni.fi.diplomka.datalayer.daoimpl.PlayerDaoImpl;
import cz.muni.fi.diplomka.datalayer.entity.PlayerEntity;
import cz.muni.fi.diplomka.servicelayer.dto.Player;
import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.PlayerManager;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

/**
 *
 * @author Jakub Kutil
 */
public class PlayerManagerImpl implements PlayerManager {

    private PlayerDao playerDao = new PlayerDaoImpl();
    private Mapper mapper = new DozerBeanMapper();

    @Override
    public void createPlayer(Player player) {
        if (player == null) {
            throw new IllegalArgumentException("Player cant be null");
        }

        playerDao.addPlayer(mapper.map(player, PlayerEntity.class));
    }

    @Override
    public void editPlayer(Player player) {
        if (player == null) {
            throw new IllegalArgumentException("Player cant be null");
        }
        playerDao.editPlayer(mapper.map(player, PlayerEntity.class));
    }

    @Override
    public void deletePlayer(Long playerId) {
        if (playerId == null) {
            throw new IllegalArgumentException("Player cant be null");
        }
    }

    @Override
    public Player findPlayerByLogin(String login) {
        if (login == null) {
            throw new IllegalArgumentException("Login cant be null");
        }

        return mapper.map(playerDao.findPlayerByNickName(login), Player.class);
    }

    @Override
    public Player findPlayerById(Long id) {
        if (id == null) {
            throw new IllegalArgumentException("ID cant be null");
        }

        return mapper.map(playerDao.findPlayerById(id), Player.class);
    }
}
